
from xml.etree import ElementTree

import utils
try:
    import dav_resource
except ImportError:
    pass

class XMLParsingError(Exception):
    pass

class DAVElementFactory:
    @staticmethod
    def CreateByXML(xml):
        if isinstance(xml, (str, unicode)):
            xml = ElementTree.XML(xml)
        name = 'DAV' + utils.property2variable(xml.tag[6:]).capitalize()
        result = globals()[name]()
        result.loadXML(xml)
        return result
    @staticmethod
    def CreateByTag(namespace, tagname, value=None):
        if not value:
            value = ''
        try:
            xml = ElementTree.XML(value)
            if xml.tag != '{%s}%s' % (namespace, tagname):
                raise TypeError
        except Exception:
            xml = ElementTree.XML('<%s xmlns="%s">%s</%s>' % (tagname, namespace, value, tagname))
        name = 'DAV' + utils.property2variable(tagname).capitalize()
        result = globals()[name]()
        result.loadXML(xml)
        return result

class DAVElement():
    def __init__(self):
        pass
    def __contains__(self, name):
        name = utils.property2variable(name)
        if hasattr(self, name):
            return True
        elif hasattr(self, name+'List'):
            return True
        return False
    def __getitem__(self, key):
        ns, ln = utils.separate_ns_ln(key)
        name = utils.property2variable(ln)
        if hasattr(self, name):
            return getattr(self, name)
        elif hasattr(self, name+'List'):
            return getattr(self, name + 'List')
        raise ValueError
    def __setitem__(self, key, value):
        ns, ln = utils.separate_ns_ln(key)
        name = utils.property2variable(ln)
        self.__dict__[name] = value
    def getchildren(self):
        result = []
        for k, v in self.__dict__.items():
            if k in self.children and v:
                result.append(v)
        return result
    def getXMLElement(self):
        pass
    def loadXML(self, xmlStr):
        pass
    def dumpXML(self, encoding='UTF-8'):
        return ElementTree.tostring(self.getXMLElement(), encoding=encoding)
    @property
    def XML(self):
        return self.dumpXML(encoding=None)

class DAV_self(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}self'
    def getValue(self):
        if self.__dict__['self']:
            return self.__dict__[utils.property2variable('self')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('self')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}self')
        return elmt

class DAVExclusive(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}exclusive'
    def getValue(self):
        if self.__dict__['exclusive']:
            return self.__dict__[utils.property2variable('exclusive')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('exclusive')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}exclusive')
        return elmt

class DAVAll(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}all'
    def getValue(self):
        if self.__dict__['all']:
            return self.__dict__[utils.property2variable('all')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('all')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}all')
        return elmt

class DAVGetetag(DAVElement):
    def __init__(self, getetag=str(), ):
        self.children = ['getetag']
        if getetag:
            self.getetag = getetag
        else:
            self.getetag = str()
        pass
    def getTag(self):
        return '{DAV:}getetag'
    def getValue(self):
        if self.__dict__['getetag']:
            return self.__dict__[utils.property2variable('getetag')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('getetag')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.getetag = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}getetag')
        if self.getetag:
            elmt.text = self.getetag
        return elmt

class DAVNo_conflicting_lock(DAVElement):
    def __init__(self, hrefList=list(), ):
        self.children = ['hrefList']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
    def getTag(self):
        return '{DAV:}no-conflicting-lock'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}no-conflicting-lock')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVResourcetype(DAVElement):
    def __init__(self, collection=None, principal=None, ):
        self.children = ['collection', 'principal']
        if collection:
            self.collection = collection
        else:
            self.collection = None
        if principal:
            self.principal = principal
        else:
            self.principal = None
    def getTag(self):
        return '{DAV:}resourcetype'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}collection':
                self.collection = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}principal':
                self.principal = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}resourcetype')
        if self.collection:
            elmt.append(self.collection.getXMLElement())
        if self.principal:
            elmt.append(self.principal.getXMLElement())
        return elmt

class DAVLock_token_submitted(DAVElement):
    def __init__(self, hrefList=list(), ):
        self.children = ['hrefList']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
    def getTag(self):
        return '{DAV:}lock-token-submitted'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}lock-token-submitted')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVMultistatus(DAVElement):
    def __init__(self, responseList=list(), responsedescription=None, ):
        self.children = ['responseList', 'responsedescription']
        if responseList:
            self.responseList = responseList
        else:
            self.responseList = list()
        if responsedescription:
            self.responsedescription = responsedescription
        else:
            self.responsedescription = None
    def getTag(self):
        return '{DAV:}multistatus'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}response':
                self.responseList.append(DAVElementFactory.CreateByXML(one))
            elif one.tag == '{DAV:}responsedescription':
                self.responsedescription = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}multistatus')
        if self.responseList:
            for one in self.responseList:
                elmt.append(one.getXMLElement())
        if self.responsedescription:
            elmt.append(self.responsedescription.getXMLElement())
        return elmt

class DAVGetlastmodified(DAVElement):
    def __init__(self, getlastmodified=str(), ):
        self.children = ['getlastmodified']
        if getlastmodified:
            self.getlastmodified = getlastmodified
        else:
            self.getlastmodified = str()
        pass
    def getTag(self):
        return '{DAV:}getlastmodified'
    def getValue(self):
        if self.__dict__['getlastmodified']:
            return self.__dict__[utils.property2variable('getlastmodified')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('getlastmodified')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.getlastmodified = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}getlastmodified')
        if self.getlastmodified:
            elmt.text = self.getlastmodified
        return elmt

class DAVGetcontentlength(DAVElement):
    def __init__(self, getcontentlength=str(), ):
        self.children = ['getcontentlength']
        if getcontentlength:
            self.getcontentlength = getcontentlength
        else:
            self.getcontentlength = str()
        pass
    def getTag(self):
        return '{DAV:}getcontentlength'
    def getValue(self):
        if self.__dict__['getcontentlength']:
            return self.__dict__[utils.property2variable('getcontentlength')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('getcontentlength')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.getcontentlength = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}getcontentlength')
        if self.getcontentlength:
            elmt.text = self.getcontentlength
        return elmt

class DAVPrincipal(DAVElement):
    def __init__(self, href=None, all=None, authenticated=None, unauthenticated=None, property=None, _self=None, ):
        self.children = ['href', 'all', 'authenticated', 'unauthenticated', 'property', '_self']
        if href:
            self.href = href
        else:
            self.href = None
        if all:
            self.all = all
        else:
            self.all = None
        if authenticated:
            self.authenticated = authenticated
        else:
            self.authenticated = None
        if unauthenticated:
            self.unauthenticated = unauthenticated
        else:
            self.unauthenticated = None
        if property:
            self.property = property
        else:
            self.property = None
        if _self:
            self._self = _self
        else:
            self._self = None
    def getTag(self):
        return '{DAV:}principal'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}all':
                self.all = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}authenticated':
                self.authenticated = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}unauthenticated':
                self.unauthenticated = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}property':
                self.property = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}_self':
                self._self = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}principal')
        if self.href:
            elmt.append(self.href.getXMLElement())
        if self.all:
            elmt.append(self.all.getXMLElement())
        if self.authenticated:
            elmt.append(self.authenticated.getXMLElement())
        if self.unauthenticated:
            elmt.append(self.unauthenticated.getXMLElement())
        if self.property:
            elmt.append(self.property.getXMLElement())
        if self._self:
            elmt.append(self._self.getXMLElement())
        return elmt
    @property
    def TYPE(self):
        if self.all:
            return 'all'
        elif self.authenticated:
            return 'authenticated'
        elif self.unauthenticated:
            return 'unauthenticated'
        elif self.property and self.property.owner:
            return 'property.owner'
        elif self.property and self.property.group:
            return 'property.group'
        elif self.href:
            return self.href.href
    def __eq__(self, principal):
        return self.dumpXML() == principal.dumpXML()

class DAVLockroot(DAVElement):
    def __init__(self, href=None, ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = None
    def getTag(self):
        return '{DAV:}lockroot'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}lockroot')
        if self.href:
            elmt.append(self.href.getXMLElement())
        return elmt

class DAVLock_token_matches_request_uri(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}lock-token-matches-request-uri'
    def getValue(self):
        if self.__dict__['lock-token-matches-request-uri']:
            return self.__dict__[utils.property2variable('lock-token-matches-request-uri')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('lock-token-matches-request-uri')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}lock-token-matches-request-uri')
        return elmt

class DAVBind(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}bind'
    def getValue(self):
        if self.__dict__['bind']:
            return self.__dict__[utils.property2variable('bind')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('bind')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}bind')
        return elmt

class DAVGroup(DAVElement):
    def __init__(self, href=None, ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = None
    def getTag(self):
        return '{DAV:}group'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}group')
        if self.href:
            elmt.append(self.href.getXMLElement())
        return elmt
    def __contains__(self, principal):
        if self.href:
           group = dav_resource.Resource(self.href.href)
           group.loadProperties(['DAV:'], ['group-member-set'])
           for member in group.group_member_set.hrefList:
               if member.isPrincipal() and member == principal.href:
                   return True
               elif member.isGroup() and principal in DAVGroup(member):
                   return True
        return False

class DAVPrincipal_property_search(DAVElement):
    def __init__(self, property_searchList=list(), prop=None, apply_to_principal_collection_set=None, ):
        self.children = ['property_searchList', 'prop', 'apply_to_principal_collection_set']
        if property_searchList:
            self.property_searchList = property_searchList
        else:
            self.property_searchList = list()
        if prop:
            self.prop = prop
        else:
            self.prop = None
        if apply_to_principal_collection_set:
            self.apply_to_principal_collection_set = apply_to_principal_collection_set
        else:
            self.apply_to_principal_collection_set = None
    def getTag(self):
        return '{DAV:}principal-property-search'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}property-search':
                self.property_searchList.append(DAVElementFactory.CreateByXML(one))
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}apply-to-principal-collection-set':
                self.apply_to_principal_collection_set = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}principal-property-search')
        if self.property_searchList:
            for one in self.property_searchList:
                elmt.append(one.getXMLElement())
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        if self.apply_to_principal_collection_set:
            elmt.append(self.apply_to_principal_collection_set.getXMLElement())
        return elmt

class DAVLockentry(DAVElement):
    def __init__(self, lockscope=None, locktype=None, ):
        self.children = ['lockscope', 'locktype']
        if lockscope:
            self.lockscope = lockscope
        else:
            self.lockscope = None
        if locktype:
            self.locktype = locktype
        else:
            self.locktype = None
    def getTag(self):
        return '{DAV:}lockentry'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}lockscope':
                self.lockscope = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}locktype':
                self.locktype = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}lockentry')
        if self.lockscope:
            elmt.append(self.lockscope.getXMLElement())
        if self.locktype:
            elmt.append(self.locktype.getXMLElement())
        return elmt

class DAVInherited_acl_set(DAVElement):
    def __init__(self, hrefList=list(), ):
        self.children = ['hrefList']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
    def getTag(self):
        return '{DAV:}inherited-acl-set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}inherited-acl-set')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVGroup_membership(DAVElement):
    def __init__(self, hrefList=list(), ):
        self.children = ['hrefList']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
    def getTag(self):
        return '{DAV:}group-membership'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}group-membership')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVLocation(DAVElement):
    def __init__(self, href=None, ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = None
    def getTag(self):
        return '{DAV:}location'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}location')
        if self.href:
            elmt.append(self.href.getXMLElement())
        return elmt

class DAVUnauthenticated(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}unauthenticated'
    def getValue(self):
        if self.__dict__['unauthenticated']:
            return self.__dict__[utils.property2variable('unauthenticated')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('unauthenticated')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}unauthenticated')
        return elmt

class DAVWrite_content(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}write-content'
    def getValue(self):
        if self.__dict__['write-content']:
            return self.__dict__[utils.property2variable('write-content')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('write-content')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}write-content')
        return elmt

class DAVInclude(DAVElement):
    def __init__(self, creationdate=None, displayname=None, getcontentlanguage=None, getcontentlength=None, getcontenttype=None, getetag=None, getlastmodified=None, lockdiscovery=None, resourcetype=None, supportedlock=None, owner=None, group=None, group_member_set=None, group_membership=None, acl=None, ):
        self.children = ['creationdate', 'displayname', 'getcontentlanguage', 'getcontentlength', 'getcontenttype', 'getetag', 'getlastmodified', 'lockdiscovery', 'resourcetype', 'supportedlock', 'owner', 'group', 'group_member_set', 'group_membership', 'acl']
        if creationdate:
            self.creationdate = creationdate
        else:
            self.creationdate = None
        if displayname:
            self.displayname = displayname
        else:
            self.displayname = None
        if getcontentlanguage:
            self.getcontentlanguage = getcontentlanguage
        else:
            self.getcontentlanguage = None
        if getcontentlength:
            self.getcontentlength = getcontentlength
        else:
            self.getcontentlength = None
        if getcontenttype:
            self.getcontenttype = getcontenttype
        else:
            self.getcontenttype = None
        if getetag:
            self.getetag = getetag
        else:
            self.getetag = None
        if getlastmodified:
            self.getlastmodified = getlastmodified
        else:
            self.getlastmodified = None
        if lockdiscovery:
            self.lockdiscovery = lockdiscovery
        else:
            self.lockdiscovery = None
        if resourcetype:
            self.resourcetype = resourcetype
        else:
            self.resourcetype = None
        if supportedlock:
            self.supportedlock = supportedlock
        else:
            self.supportedlock = None
        if owner:
            self.owner = owner
        else:
            self.owner = None
        if group:
            self.group = group
        else:
            self.group = None
        if group_member_set:
            self.group_member_set = group_member_set
        else:
            self.group_member_set = None
        if group_membership:
            self.group_membership = group_membership
        else:
            self.group_membership = None
        if acl:
            self.acl = acl
        else:
            self.acl = None
    def getTag(self):
        return '{DAV:}include'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}creationdate':
                self.creationdate = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}displayname':
                self.displayname = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontentlanguage':
                self.getcontentlanguage = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontentlength':
                self.getcontentlength = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontenttype':
                self.getcontenttype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getetag':
                self.getetag = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getlastmodified':
                self.getlastmodified = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}lockdiscovery':
                self.lockdiscovery = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}resourcetype':
                self.resourcetype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}supportedlock':
                self.supportedlock = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}owner':
                self.owner = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group':
                self.group = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group-member-set':
                self.group_member_set = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group-membership':
                self.group_membership = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}acl':
                self.acl = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}include')
        if self.creationdate:
            elmt.append(self.creationdate.getXMLElement())
        if self.displayname:
            elmt.append(self.displayname.getXMLElement())
        if self.getcontentlanguage:
            elmt.append(self.getcontentlanguage.getXMLElement())
        if self.getcontentlength:
            elmt.append(self.getcontentlength.getXMLElement())
        if self.getcontenttype:
            elmt.append(self.getcontenttype.getXMLElement())
        if self.getetag:
            elmt.append(self.getetag.getXMLElement())
        if self.getlastmodified:
            elmt.append(self.getlastmodified.getXMLElement())
        if self.lockdiscovery:
            elmt.append(self.lockdiscovery.getXMLElement())
        if self.resourcetype:
            elmt.append(self.resourcetype.getXMLElement())
        if self.supportedlock:
            elmt.append(self.supportedlock.getXMLElement())
        if self.owner:
            elmt.append(self.owner.getXMLElement())
        if self.group:
            elmt.append(self.group.getXMLElement())
        if self.group_member_set:
            elmt.append(self.group_member_set.getXMLElement())
        if self.group_membership:
            elmt.append(self.group_membership.getXMLElement())
        if self.acl:
            elmt.append(self.acl.getXMLElement())
        return elmt

class DAVLocktype(DAVElement):
    def __init__(self, write=None, ):
        self.children = ['write']
        if write:
            self.write = write
        else:
            self.write = None
    def getTag(self):
        return '{DAV:}locktype'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}write':
                self.write = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}locktype')
        if self.write:
            elmt.append(self.write.getXMLElement())
        return elmt

class DAVMatch(DAVElement):
    def __init__(self, match=str(), ):
        self.children = ['match']
        if match:
            self.match = match
        else:
            self.match = str()
        pass
    def getTag(self):
        return '{DAV:}match'
    def getValue(self):
        if self.__dict__['match']:
            return self.__dict__[utils.property2variable('match')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('match')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.match = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}match')
        if self.match:
            elmt.text = self.match
        return elmt

class DAVDisplayname(DAVElement):
    def __init__(self, displayname=str(), ):
        self.children = ['displayname']
        if displayname:
            self.displayname = displayname
        else:
            self.displayname = str()
        pass
    def getTag(self):
        return '{DAV:}displayname'
    def getValue(self):
        if self.__dict__['displayname']:
            return self.__dict__[utils.property2variable('displayname')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('displayname')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.displayname = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}displayname')
        if self.displayname:
            elmt.text = self.displayname
        return elmt

class DAVAlternate_uri_set(DAVElement):
    def __init__(self, hrefList=list(), ):
        self.children = ['hrefList']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
    def getTag(self):
        return '{DAV:}alternate-URI-set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}alternate-URI-set')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVRead(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}read'
    def getValue(self):
        if self.__dict__['read']:
            return self.__dict__[utils.property2variable('read')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('read')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}read')
        return elmt

class DAVCannot_modify_protected_property(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}cannot-modify-protected-property'
    def getValue(self):
        if self.__dict__['cannot-modify-protected-property']:
            return self.__dict__[utils.property2variable('cannot-modify-protected-property')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('cannot-modify-protected-property')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}cannot-modify-protected-property')
        return elmt

class DAVResponsedescription(DAVElement):
    def __init__(self, responsedescription=str(), ):
        self.children = ['responsedescription']
        if responsedescription:
            self.responsedescription = responsedescription
        else:
            self.responsedescription = str()
        pass
    def getTag(self):
        return '{DAV:}responsedescription'
    def getValue(self):
        if self.__dict__['responsedescription']:
            return self.__dict__[utils.property2variable('responsedescription')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('responsedescription')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.responsedescription = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}responsedescription')
        if self.responsedescription:
            elmt.text = self.responsedescription
        return elmt

class DAVGetcontentlanguage(DAVElement):
    def __init__(self, getcontentlanguage=str(), ):
        self.children = ['getcontentlanguage']
        if getcontentlanguage:
            self.getcontentlanguage = getcontentlanguage
        else:
            self.getcontentlanguage = str()
        pass
    def getTag(self):
        return '{DAV:}getcontentlanguage'
    def getValue(self):
        if self.__dict__['getcontentlanguage']:
            return self.__dict__[utils.property2variable('getcontentlanguage')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('getcontentlanguage')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.getcontentlanguage = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}getcontentlanguage')
        if self.getcontentlanguage:
            elmt.text = self.getcontentlanguage
        return elmt

class DAVCurrent_user_privilege_set(DAVElement):
    def __init__(self, privilegeList=list(), ):
        self.children = ['privilegeList']
        if privilegeList:
            self.privilegeList = privilegeList
        else:
            self.privilegeList = list()
    def getTag(self):
        return '{DAV:}current-user-privilege-set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}privilege':
                self.privilegeList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}current-user-privilege-set')
        if self.privilegeList:
            for one in self.privilegeList:
                elmt.append(one.getXMLElement())
        return elmt
    def __contains__(self, privilege):
        for one in self.privilegeList:
            if privilege in one:
                return True
        return False
    def append(self, privilegeList):
        for pv in privilegeList:
            flag = True
            for opv in self.privilegeList:
                if opv in pv:
                    self.privilegeList.remove(opv)
                elif pv in opv:
                    flag = False
            if flag:
                self.privilegeList.append(pv)
    def remove(self, privilegeList):
        for pv in privilegeList:
            for opv in self.privilegeList:
                if opv in pv:
                    self.privilegeList.remove(opv)

class DAVResource(DAVElement):
    def __init__(self, href=None, privilege=None, ):
        self.children = ['href', 'privilege']
        if href:
            self.href = href
        else:
            self.href = None
        if privilege:
            self.privilege = privilege
        else:
            self.privilege = None
    def getTag(self):
        return '{DAV:}resource'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}privilege':
                self.privilege = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}resource')
        if self.href:
            elmt.append(self.href.getXMLElement())
        if self.privilege:
            elmt.append(self.privilege.getXMLElement())
        return elmt

class DAVRemove(DAVElement):
    def __init__(self, prop=None, ):
        self.children = ['prop']
        if prop:
            self.prop = prop
        else:
            self.prop = None
    def getTag(self):
        return '{DAV:}remove'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}remove')
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        return elmt

class DAVTimeout(DAVElement):
    def __init__(self, timeout=str(), ):
        self.children = ['timeout']
        if timeout:
            self.timeout = timeout
        else:
            self.timeout = str()
        pass
    def getTag(self):
        return '{DAV:}timeout'
    def getValue(self):
        if self.__dict__['timeout']:
            return self.__dict__[utils.property2variable('timeout')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('timeout')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.timeout = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}timeout')
        if self.timeout:
            elmt.text = self.timeout
        return elmt

class DAVPrincipal_url(DAVElement):
    def __init__(self, href=None, ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = None
    def getTag(self):
        return '{DAV:}principal-URL'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}principal-URL')
        if self.href:
            elmt.append(self.href.getXMLElement())
        return elmt

class DAVSet(DAVElement):
    def __init__(self, prop=None, ):
        self.children = ['prop']
        if prop:
            self.prop = prop
        else:
            self.prop = None
    def getTag(self):
        return '{DAV:}set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}set')
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        return elmt

class DAVDeny_before_grant(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}deny-before-grant'
    def getValue(self):
        if self.__dict__['deny-before-grant']:
            return self.__dict__[utils.property2variable('deny-before-grant')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('deny-before-grant')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}deny-before-grant')
        return elmt

class DAVUnlock(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}unlock'
    def getValue(self):
        if self.__dict__['unlock']:
            return self.__dict__[utils.property2variable('unlock')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('unlock')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}unlock')
        return elmt

class DAVNo_external_entities(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}no-external-entities'
    def getValue(self):
        if self.__dict__['no-external-entities']:
            return self.__dict__[utils.property2variable('no-external-entities')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('no-external-entities')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}no-external-entities')
        return elmt

class DAVSupportedlock(DAVElement):
    def __init__(self, lockentryList=list(), ):
        self.children = ['lockentryList']
        if lockentryList:
            self.lockentryList = lockentryList
        else:
            self.lockentryList = list()
    def getTag(self):
        return '{DAV:}supportedlock'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}lockentry':
                self.lockentryList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}supportedlock')
        if self.lockentryList:
            for one in self.lockentryList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVRead_current_user_privilege_set(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}read-current-user-privilege-set'
    def getValue(self):
        if self.__dict__['read-current-user-privilege-set']:
            return self.__dict__[utils.property2variable('read-current-user-privilege-set')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('read-current-user-privilege-set')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}read-current-user-privilege-set')
        return elmt

class DAVPropertyupdate(DAVElement):
    def __init__(self, removeList=list(), setList=list(), ):
        self.children = ['removeList', 'setList']
        if removeList:
            self.removeList = removeList
        else:
            self.removeList = list()
        if setList:
            self.setList = setList
        else:
            self.setList = list()
    def getTag(self):
        return '{DAV:}propertyupdate'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}remove':
                self.removeList.append(DAVElementFactory.CreateByXML(one))
            elif one.tag == '{DAV:}set':
                self.setList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}propertyupdate')
        if self.removeList:
            for one in self.removeList:
                elmt.append(one.getXMLElement())
        if self.setList:
            for one in self.setList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVAcl_restrictions(DAVElement):
    def __init__(self, grant_only=None, no_invert=None, deny_before_grant=None, required_principal=None, ):
        self.children = ['grant_only', 'no_invert', 'deny_before_grant', 'required_principal']
        if grant_only:
            self.grant_only = grant_only
        else:
            self.grant_only = None
        if no_invert:
            self.no_invert = no_invert
        else:
            self.no_invert = None
        if deny_before_grant:
            self.deny_before_grant = deny_before_grant
        else:
            self.deny_before_grant = None
        if required_principal:
            self.required_principal = required_principal
        else:
            self.required_principal = None
    def getTag(self):
        return '{DAV:}acl-restrictions'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}grant-only':
                self.grant_only = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}no-invert':
                self.no_invert = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}deny-before-grant':
                self.deny_before_grant = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}required-principal':
                self.required_principal = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}acl-restrictions')
        if self.grant_only:
            elmt.append(self.grant_only.getXMLElement())
        if self.no_invert:
            elmt.append(self.no_invert.getXMLElement())
        if self.deny_before_grant:
            elmt.append(self.deny_before_grant.getXMLElement())
        if self.required_principal:
            elmt.append(self.required_principal.getXMLElement())
        return elmt

class DAVProp(DAVElement):
    def __init__(self, creationdate=None, displayname=None, getcontentlanguage=None, getcontentlength=None, getcontenttype=None, getetag=None, getlastmodified=None, lockdiscovery=None, resourcetype=None, supportedlock=None, owner=None, group=None, group_member_set=None, group_membership=None, acl=None, current_user_privilege_set=None, ):
        self.children = ['creationdate', 'displayname', 'getcontentlanguage', 'getcontentlength', 'getcontenttype', 'getetag', 'getlastmodified', 'lockdiscovery', 'resourcetype', 'supportedlock', 'owner', 'group', 'group_member_set', 'group_membership', 'acl', 'current_user_privilege_set']
        if creationdate:
            self.creationdate = creationdate
        else:
            self.creationdate = None
        if displayname:
            self.displayname = displayname
        else:
            self.displayname = None
        if getcontentlanguage:
            self.getcontentlanguage = getcontentlanguage
        else:
            self.getcontentlanguage = None
        if getcontentlength:
            self.getcontentlength = getcontentlength
        else:
            self.getcontentlength = None
        if getcontenttype:
            self.getcontenttype = getcontenttype
        else:
            self.getcontenttype = None
        if getetag:
            self.getetag = getetag
        else:
            self.getetag = None
        if getlastmodified:
            self.getlastmodified = getlastmodified
        else:
            self.getlastmodified = None
        if lockdiscovery:
            self.lockdiscovery = lockdiscovery
        else:
            self.lockdiscovery = None
        if resourcetype:
            self.resourcetype = resourcetype
        else:
            self.resourcetype = None
        if supportedlock:
            self.supportedlock = supportedlock
        else:
            self.supportedlock = None
        if owner:
            self.owner = owner
        else:
            self.owner = None
        if group:
            self.group = group
        else:
            self.group = None
        if group_member_set:
            self.group_member_set = group_member_set
        else:
            self.group_member_set = None
        if group_membership:
            self.group_membership = group_membership
        else:
            self.group_membership = None
        if acl:
            self.acl = acl
        else:
            self.acl = None
        if current_user_privilege_set:
            self.current_user_privilege_set = current_user_privilege_set
        else:
            self.current_user_privilege_set = None
    def getTag(self):
        return '{DAV:}prop'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}creationdate':
                self.creationdate = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}displayname':
                self.displayname = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontentlanguage':
                self.getcontentlanguage = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontentlength':
                self.getcontentlength = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontenttype':
                self.getcontenttype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getetag':
                self.getetag = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getlastmodified':
                self.getlastmodified = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}lockdiscovery':
                self.lockdiscovery = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}resourcetype':
                self.resourcetype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}supportedlock':
                self.supportedlock = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}owner':
                self.owner = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group':
                self.group = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group-member-set':
                self.group_member_set = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group-membership':
                self.group_membership = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}acl':
                self.acl = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}current-user-privilege-set':
                self.current_user_privilege_set = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}prop')
        if self.creationdate:
            elmt.append(self.creationdate.getXMLElement())
        if self.displayname:
            elmt.append(self.displayname.getXMLElement())
        if self.getcontentlanguage:
            elmt.append(self.getcontentlanguage.getXMLElement())
        if self.getcontentlength:
            elmt.append(self.getcontentlength.getXMLElement())
        if self.getcontenttype:
            elmt.append(self.getcontenttype.getXMLElement())
        if self.getetag:
            elmt.append(self.getetag.getXMLElement())
        if self.getlastmodified:
            elmt.append(self.getlastmodified.getXMLElement())
        if self.lockdiscovery:
            elmt.append(self.lockdiscovery.getXMLElement())
        if self.resourcetype:
            elmt.append(self.resourcetype.getXMLElement())
        if self.supportedlock:
            elmt.append(self.supportedlock.getXMLElement())
        if self.owner:
            elmt.append(self.owner.getXMLElement())
        if self.group:
            elmt.append(self.group.getXMLElement())
        if self.group_member_set:
            elmt.append(self.group_member_set.getXMLElement())
        if self.group_membership:
            elmt.append(self.group_membership.getXMLElement())
        if self.acl:
            elmt.append(self.acl.getXMLElement())
        if self.current_user_privilege_set:
            elmt.append(self.current_user_privilege_set.getXMLElement())
        return elmt

class DAVShared(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}shared'
    def getValue(self):
        if self.__dict__['shared']:
            return self.__dict__[utils.property2variable('shared')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('shared')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}shared')
        return elmt

class DAVWrite_properties(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}write-properties'
    def getValue(self):
        if self.__dict__['write-properties']:
            return self.__dict__[utils.property2variable('write-properties')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('write-properties')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}write-properties')
        return elmt

class DAVPropfind_finite_depth(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}propfind-finite-depth'
    def getValue(self):
        if self.__dict__['propfind-finite-depth']:
            return self.__dict__[utils.property2variable('propfind-finite-depth')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('propfind-finite-depth')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}propfind-finite-depth')
        return elmt

class DAVLockscope(DAVElement):
    def __init__(self, exclusive=None, shared=None, ):
        self.children = ['exclusive', 'shared']
        if exclusive:
            self.exclusive = exclusive
        else:
            self.exclusive = None
        if shared:
            self.shared = shared
        else:
            self.shared = None
    def getTag(self):
        return '{DAV:}lockscope'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}exclusive':
                self.exclusive = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}shared':
                self.shared = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}lockscope')
        if self.exclusive:
            elmt.append(self.exclusive.getXMLElement())
        if self.shared:
            elmt.append(self.shared.getXMLElement())
        return elmt

class DAVPrincipal_match(DAVElement):
    def __init__(self, principal_property=None, _self=None, prop=None, ):
        self.children = ['principal_property', '_self', 'prop']
        if principal_property:
            self.principal_property = principal_property
        else:
            self.principal_property = None
        if _self:
            self._self = _self
        else:
            self._self = None
        if prop:
            self.prop = prop
        else:
            self.prop = None
    def getTag(self):
        return '{DAV:}principal-match'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}principal-property':
                self.principal_property = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}_self':
                self._self = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}principal-match')
        if self.principal_property:
            elmt.append(self.principal_property.getXMLElement())
        if self._self:
            elmt.append(self._self.getXMLElement())
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        return elmt

class DAVAce(DAVElement):
    def __init__(self, principal=None, invert=None, grant=None, deny=None, protected=None, inherited=None, ):
        self.children = ['principal', 'invert', 'grant', 'deny', 'protected', 'inherited']
        if principal:
            self.principal = principal
        else:
            self.principal = None
        if invert:
            self.invert = invert
        else:
            self.invert = None
        if grant:
            self.grant = grant
        else:
            self.grant = None
        if deny:
            self.deny = deny
        else:
            self.deny = None
        if protected:
            self.protected = protected
        else:
            self.protected = None
        if inherited:
            self.inherited = inherited
        else:
            self.inherited = None
    def getTag(self):
        return '{DAV:}ace'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}principal':
                self.principal = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}invert':
                self.invert = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}grant':
                self.grant = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}deny':
                self.deny = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}protected':
                self.protected = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}inherited':
                self.inherited = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}ace')
        if self.principal:
            elmt.append(self.principal.getXMLElement())
        if self.invert:
            elmt.append(self.invert.getXMLElement())
        if self.grant:
            elmt.append(self.grant.getXMLElement())
        if self.deny:
            elmt.append(self.deny.getXMLElement())
        if self.protected:
            elmt.append(self.protected.getXMLElement())
        if self.inherited:
            elmt.append(self.inherited.getXMLElement())
        return elmt
    def __eq__(self, ace):
        if self.grant and ace.grant or self.deny and ace.deny:
            return self.principal == ace.principal
        else:
            return False
    def update(self, ace):
        if self.grant and ace.grant:
            oldpvList = self.grant.privilegeList
            newpvList = ace.grant.privilegeList
        elif self.deny and ace.deny:
            oldpvList = self.deny.privilegeList
            newpvList = ace.deny.privilegeList
        else:
            return
        for newpv in newpvList:
            flag = True
            for oldpv in oldpvList:
                if newpv in oldpv:
                   flag = False
            if flag:
                oldpvList.append(newpv)

class DAVActivelock(DAVElement):
    def __init__(self, lockscope=None, locktype=None, depth=None, owner=None, timeout=None, locktoken=None, lockroot=None, ):
        self.children = ['lockscope', 'locktype', 'depth', 'owner', 'timeout', 'locktoken', 'lockroot']
        if lockscope:
            self.lockscope = lockscope
        else:
            self.lockscope = None
        if locktype:
            self.locktype = locktype
        else:
            self.locktype = None
        if depth:
            self.depth = depth
        else:
            self.depth = None
        if owner:
            self.owner = owner
        else:
            self.owner = None
        if timeout:
            self.timeout = timeout
        else:
            self.timeout = None
        if locktoken:
            self.locktoken = locktoken
        else:
            self.locktoken = None
        if lockroot:
            self.lockroot = lockroot
        else:
            self.lockroot = None
    def getTag(self):
        return '{DAV:}activelock'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}lockscope':
                self.lockscope = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}locktype':
                self.locktype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}depth':
                self.depth = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}owner':
                self.owner = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}timeout':
                self.timeout = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}locktoken':
                self.locktoken = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}lockroot':
                self.lockroot = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}activelock')
        if self.lockscope:
            elmt.append(self.lockscope.getXMLElement())
        if self.locktype:
            elmt.append(self.locktype.getXMLElement())
        if self.depth:
            elmt.append(self.depth.getXMLElement())
        if self.owner:
            elmt.append(self.owner.getXMLElement())
        if self.timeout:
            elmt.append(self.timeout.getXMLElement())
        if self.locktoken:
            elmt.append(self.locktoken.getXMLElement())
        if self.lockroot:
            elmt.append(self.lockroot.getXMLElement())
        return elmt

class DAVAllprop(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}allprop'
    def getValue(self):
        if self.__dict__['allprop']:
            return self.__dict__[utils.property2variable('allprop')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('allprop')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}allprop')
        return elmt

class DAVNo_invert(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}no-invert'
    def getValue(self):
        if self.__dict__['no-invert']:
            return self.__dict__[utils.property2variable('no-invert')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('no-invert')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}no-invert')
        return elmt

class DAVLocktoken(DAVElement):
    def __init__(self, href=None, ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = None
    def getTag(self):
        return '{DAV:}locktoken'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}locktoken')
        if self.href:
            elmt.append(self.href.getXMLElement())
        return elmt

class DAVLockdiscovery(DAVElement):
    def __init__(self, activelockList=list(), ):
        self.children = ['activelockList']
        if activelockList:
            self.activelockList = activelockList
        else:
            self.activelockList = list()
    def getTag(self):
        return '{DAV:}lockdiscovery'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}activelock':
                self.activelockList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}lockdiscovery')
        if self.activelockList:
            for one in self.activelockList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVPropfind(DAVElement):
    def __init__(self, propname=None, allprop=None, include=None, prop=None, ):
        self.children = ['propname', 'allprop', 'include', 'prop']
        if propname:
            self.propname = propname
        else:
            self.propname = None
        if allprop:
            self.allprop = allprop
        else:
            self.allprop = None
        if include:
            self.include = include
        else:
            self.include = None
        if prop:
            self.prop = prop
        else:
            self.prop = None
    def getTag(self):
        return '{DAV:}propfind'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}propname':
                self.propname = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}allprop':
                self.allprop = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}include':
                self.include = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}propfind')
        if self.propname:
            elmt.append(self.propname.getXMLElement())
        if self.allprop:
            elmt.append(self.allprop.getXMLElement())
        if self.include:
            elmt.append(self.include.getXMLElement())
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        return elmt

class DAVPrincipal_collection_set(DAVElement):
    def __init__(self, hrefList=list(), ):
        self.children = ['hrefList']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
    def getTag(self):
        return '{DAV:}principal-collection-set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}principal-collection-set')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVHref(DAVElement):
    def __init__(self, href=str(), ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = str()
        pass
    def getTag(self):
        return '{DAV:}href'
    def getValue(self):
        if self.__dict__['href']:
            return self.__dict__[utils.property2variable('href')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('href')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.href = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}href')
        if self.href:
            elmt.text = self.href
        return elmt
    def __eq__(self, href):
        return self.href == href.href
    def isPrincipal(self):
        return self.href.startswith('/users/')
    def isGroup(self):
        return self.href.startswith('/groups/')

class DAVPropname(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}propname'
    def getValue(self):
        if self.__dict__['propname']:
            return self.__dict__[utils.property2variable('propname')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('propname')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}propname')
        return elmt

class DAVOwner(DAVElement):
    def __init__(self, href=None, ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = None
    def getTag(self):
        return '{DAV:}owner'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}owner')
        if self.href:
            elmt.append(self.href.getXMLElement())
        return elmt

class DAVLockinfo(DAVElement):
    def __init__(self, lockscope=None, locktype=None, owner=None, ):
        self.children = ['lockscope', 'locktype', 'owner']
        if lockscope:
            self.lockscope = lockscope
        else:
            self.lockscope = None
        if locktype:
            self.locktype = locktype
        else:
            self.locktype = None
        if owner:
            self.owner = owner
        else:
            self.owner = None
    def getTag(self):
        return '{DAV:}lockinfo'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}lockscope':
                self.lockscope = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}locktype':
                self.locktype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}owner':
                self.owner = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}lockinfo')
        if self.lockscope:
            elmt.append(self.lockscope.getXMLElement())
        if self.locktype:
            elmt.append(self.locktype.getXMLElement())
        if self.owner:
            elmt.append(self.owner.getXMLElement())
        return elmt

class DAVRequired_principal(DAVElement):
    def __init__(self, all=None, authenticated=None, unauthenticated=None, _self=None, hrefList=list(), propertyList=list(), ):
        self.children = ['all', 'authenticated', 'unauthenticated', '_self', 'hrefList', 'propertyList']
        if all:
            self.all = all
        else:
            self.all = None
        if authenticated:
            self.authenticated = authenticated
        else:
            self.authenticated = None
        if unauthenticated:
            self.unauthenticated = unauthenticated
        else:
            self.unauthenticated = None
        if _self:
            self._self = _self
        else:
            self._self = None
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
        if propertyList:
            self.propertyList = propertyList
        else:
            self.propertyList = list()
    def getTag(self):
        return '{DAV:}required-principal'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}all':
                self.all = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}authenticated':
                self.authenticated = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}unauthenticated':
                self.unauthenticated = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}self':
                self._self = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            elif one.tag == '{DAV:}property':
                self.propertyList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}required-principal')
        if self.all:
            elmt.append(self.all.getXMLElement())
        if self.authenticated:
            elmt.append(self.authenticated.getXMLElement())
        if self.unauthenticated:
            elmt.append(self.unauthenticated.getXMLElement())
        if self._self:
            elmt.append(self._self.getXMLElement())
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        if self.propertyList:
            for one in self.propertyList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVPrincipal_property(DAVElement):
    def __init__(self, creationdate=None, displayname=None, getcontentlanguage=None, getcontentlength=None, getcontenttype=None, getetag=None, getlastmodified=None, lockdiscovery=None, resourcetype=None, supportedlock=None, owner=None, group=None, group_member_set=None, group_membership=None, acl=None, ):
        self.children = ['creationdate', 'displayname', 'getcontentlanguage', 'getcontentlength', 'getcontenttype', 'getetag', 'getlastmodified', 'lockdiscovery', 'resourcetype', 'supportedlock', 'owner', 'group', 'group_member_set', 'group_membership', 'acl']
        if creationdate:
            self.creationdate = creationdate
        else:
            self.creationdate = None
        if displayname:
            self.displayname = displayname
        else:
            self.displayname = None
        if getcontentlanguage:
            self.getcontentlanguage = getcontentlanguage
        else:
            self.getcontentlanguage = None
        if getcontentlength:
            self.getcontentlength = getcontentlength
        else:
            self.getcontentlength = None
        if getcontenttype:
            self.getcontenttype = getcontenttype
        else:
            self.getcontenttype = None
        if getetag:
            self.getetag = getetag
        else:
            self.getetag = None
        if getlastmodified:
            self.getlastmodified = getlastmodified
        else:
            self.getlastmodified = None
        if lockdiscovery:
            self.lockdiscovery = lockdiscovery
        else:
            self.lockdiscovery = None
        if resourcetype:
            self.resourcetype = resourcetype
        else:
            self.resourcetype = None
        if supportedlock:
            self.supportedlock = supportedlock
        else:
            self.supportedlock = None
        if owner:
            self.owner = owner
        else:
            self.owner = None
        if group:
            self.group = group
        else:
            self.group = None
        if group_member_set:
            self.group_member_set = group_member_set
        else:
            self.group_member_set = None
        if group_membership:
            self.group_membership = group_membership
        else:
            self.group_membership = None
        if acl:
            self.acl = acl
        else:
            self.acl = None
    def getTag(self):
        return '{DAV:}principal-property'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}creationdate':
                self.creationdate = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}displayname':
                self.displayname = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontentlanguage':
                self.getcontentlanguage = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontentlength':
                self.getcontentlength = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getcontenttype':
                self.getcontenttype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getetag':
                self.getetag = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}getlastmodified':
                self.getlastmodified = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}lockdiscovery':
                self.lockdiscovery = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}resourcetype':
                self.resourcetype = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}supportedlock':
                self.supportedlock = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}owner':
                self.owner = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group':
                self.group = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group-member-set':
                self.group_member_set = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group-membership':
                self.group_membership = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}acl':
                self.acl = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}principal-property')
        if self.creationdate:
            elmt.append(self.creationdate.getXMLElement())
        if self.displayname:
            elmt.append(self.displayname.getXMLElement())
        if self.getcontentlanguage:
            elmt.append(self.getcontentlanguage.getXMLElement())
        if self.getcontentlength:
            elmt.append(self.getcontentlength.getXMLElement())
        if self.getcontenttype:
            elmt.append(self.getcontenttype.getXMLElement())
        if self.getetag:
            elmt.append(self.getetag.getXMLElement())
        if self.getlastmodified:
            elmt.append(self.getlastmodified.getXMLElement())
        if self.lockdiscovery:
            elmt.append(self.lockdiscovery.getXMLElement())
        if self.resourcetype:
            elmt.append(self.resourcetype.getXMLElement())
        if self.supportedlock:
            elmt.append(self.supportedlock.getXMLElement())
        if self.owner:
            elmt.append(self.owner.getXMLElement())
        if self.group:
            elmt.append(self.group.getXMLElement())
        if self.group_member_set:
            elmt.append(self.group_member_set.getXMLElement())
        if self.group_membership:
            elmt.append(self.group_membership.getXMLElement())
        if self.acl:
            elmt.append(self.acl.getXMLElement())
        return elmt

class DAVInvert(DAVElement):
    def __init__(self, principal=None, ):
        self.children = ['principal']
        if principal:
            self.principal = principal
        else:
            self.principal = None
    def getTag(self):
        return '{DAV:}invert'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}principal':
                self.principal = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}invert')
        if self.principal:
            elmt.append(self.principal.getXMLElement())
        return elmt

class DAVGrant_only(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}grant-only'
    def getValue(self):
        if self.__dict__['grant-only']:
            return self.__dict__[utils.property2variable('grant-only')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('grant-only')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}grant-only')
        return elmt

class DAVPrivilege(DAVElement):
    def __init__(self, read=None, write=None, write_properties=None, write_content=None, unlock=None, read_acl=None, read_current_user_privilege_set=None, write_acl=None, bind=None, unbind=None, all=None, ):
        self.children = ['read', 'write', 'write_properties', 'write_content', 'unlock', 'read_acl', 'read_current_user_privilege_set', 'write_acl', 'bind', 'unbind', 'all']
        if read:
            self.read = read
        else:
            self.read = None
        if write:
            self.write = write
        else:
            self.write = None
        if write_properties:
            self.write_properties = write_properties
        else:
            self.write_properties = None
        if write_content:
            self.write_content = write_content
        else:
            self.write_content = None
        if unlock:
            self.unlock = unlock
        else:
            self.unlock = None
        if read_acl:
            self.read_acl = read_acl
        else:
            self.read_acl = None
        if read_current_user_privilege_set:
            self.read_current_user_privilege_set = read_current_user_privilege_set
        else:
            self.read_current_user_privilege_set = None
        if write_acl:
            self.write_acl = write_acl
        else:
            self.write_acl = None
        if bind:
            self.bind = bind
        else:
            self.bind = None
        if unbind:
            self.unbind = unbind
        else:
            self.unbind = None
        if all:
            self.all = all
        else:
            self.all = None
    def getTag(self):
        return '{DAV:}privilege'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}read':
                self.read = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}write':
                self.write = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}write-properties':
                self.write_properties = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}write-content':
                self.write_content = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}unlock':
                self.unlock = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}read-acl':
                self.read_acl = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}read-current-user-privilege-set':
                self.read_current_user_privilege_set = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}write-acl':
                self.write_acl = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}bind':
                self.bind = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}unbind':
                self.unbind = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}all':
                self.all = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}privilege')
        if self.read:
            elmt.append(self.read.getXMLElement())
        if self.write:
            elmt.append(self.write.getXMLElement())
        if self.write_properties:
            elmt.append(self.write_properties.getXMLElement())
        if self.write_content:
            elmt.append(self.write_content.getXMLElement())
        if self.unlock:
            elmt.append(self.unlock.getXMLElement())
        if self.read_acl:
            elmt.append(self.read_acl.getXMLElement())
        if self.read_current_user_privilege_set:
            elmt.append(self.read_current_user_privilege_set.getXMLElement())
        if self.write_acl:
            elmt.append(self.write_acl.getXMLElement())
        if self.bind:
            elmt.append(self.bind.getXMLElement())
        if self.unbind:
            elmt.append(self.unbind.getXMLElement())
        if self.all:
            elmt.append(self.all.getXMLElement())
        return elmt
    def __contains__(self, privilege):
        if not isinstance(privilege, DAVElement):
            privilege_xml = '<privilege xmlns="DAV:">'+DAVElementFactory.CreateByTag(*utils.separate_ns_ln(privilege)).dumpXML(encoding=None) + '</privilege>'
            privilege = DAVPrivilege()
            privilege.loadXML(privilege_xml)
        if self.all:
            return True
        elif self.read and (privilege.read_acl or privilege.read_current_user_privilege_set):
            return True
        elif self.write and (privilege.write_properties or privilege.write_content):
            return True
        elif self.dumpXML() == privilege.dumpXML():
            return True
        else:
            return False

class DAVNeed_privileges(DAVElement):
    def __init__(self, resourceList=list(), ):
        self.children = ['resourceList']
        if resourceList:
            self.resourceList = resourceList
        else:
            self.resourceList = list()
    def getTag(self):
        return '{DAV:}need-privileges'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}resource':
                self.resourceList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}need-privileges')
        if self.resourceList:
            for one in self.resourceList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVInherited(DAVElement):
    def __init__(self, href=None, ):
        self.children = ['href']
        if href:
            self.href = href
        else:
            self.href = None
    def getTag(self):
        return '{DAV:}inherited'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.href = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}inherited')
        if self.href:
            elmt.append(self.href.getXMLElement())
        return elmt

class DAVUnbind(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}unbind'
    def getValue(self):
        if self.__dict__['unbind']:
            return self.__dict__[utils.property2variable('unbind')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('unbind')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}unbind')
        return elmt

class DAVGroup_member_set(DAVElement):
    def __init__(self, hrefList=list(), ):
        self.children = ['hrefList']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
    def getTag(self):
        return '{DAV:}group-member-set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}group-member-set')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVGetcontenttype(DAVElement):
    def __init__(self, getcontenttype=str(), ):
        self.children = ['getcontenttype']
        if getcontenttype:
            self.getcontenttype = getcontenttype
        else:
            self.getcontenttype = str()
        pass
    def getTag(self):
        return '{DAV:}getcontenttype'
    def getValue(self):
        if self.__dict__['getcontenttype']:
            return self.__dict__[utils.property2variable('getcontenttype')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('getcontenttype')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.getcontenttype = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}getcontenttype')
        if self.getcontenttype:
            elmt.text = self.getcontenttype
        return elmt

class DAVRead_acl(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}read-acl'
    def getValue(self):
        if self.__dict__['read-acl']:
            return self.__dict__[utils.property2variable('read-acl')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('read-acl')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}read-acl')
        return elmt

class DAVAcl_principal_prop_set(DAVElement):
    def __init__(self, prop=None, ):
        self.children = ['prop']
        if prop:
            self.prop = prop
        else:
            self.prop = None
    def getTag(self):
        return '{DAV:}acl-principal-prop-set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}acl-principal-prop-set')
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        return elmt

class DAVWrite_acl(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}write-acl'
    def getValue(self):
        if self.__dict__['write-acl']:
            return self.__dict__[utils.property2variable('write-acl')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('write-acl')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}write-acl')
        return elmt

class DAVProtected(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}protected'
    def getValue(self):
        if self.__dict__['protected']:
            return self.__dict__[utils.property2variable('protected')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('protected')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}protected')
        return elmt

class DAVError(DAVElement):
    def __init__(self, lock_token_submitted=None, need_privileges=None, ):
        self.children = ['lock_token_submitted', 'need_privileges']
        if lock_token_submitted:
            self.lock_token_submitted = lock_token_submitted
        else:
            self.lock_token_submitted = None
        if need_privileges:
            self.need_privileges = need_privileges
        else:
            self.need_privileges = None
    def getTag(self):
        return '{DAV:}error'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}lock-token-submitted':
                self.lock_token_submitted = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}need-privileges':
                self.need_privileges = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}error')
        if self.lock_token_submitted:
            elmt.append(self.lock_token_submitted.getXMLElement())
        if self.need_privileges:
            elmt.append(self.need_privileges.getXMLElement())
        return elmt

class DAVProperty(DAVElement):
    def __init__(self, owner=None, group=None, ):
        self.children = ['owner', 'group']
        if owner:
            self.owner = owner
        else:
            self.owner = None
        if group:
            self.group = group
        else:
            self.group = None
    def getTag(self):
        return '{DAV:}property'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}owner':
                self.owner = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}group':
                self.group = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}property')
        if self.owner:
            elmt.append(self.owner.getXMLElement())
        if self.group:
            elmt.append(self.group.getXMLElement())
        return elmt

class DAVProperty_search(DAVElement):
    def __init__(self, prop=None, match=None, ):
        self.children = ['prop', 'match']
        if prop:
            self.prop = prop
        else:
            self.prop = None
        if match:
            self.match = match
        else:
            self.match = None
    def getTag(self):
        return '{DAV:}property-search'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}match':
                self.match = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}property-search')
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        if self.match:
            elmt.append(self.match.getXMLElement())
        return elmt

class DAVAbstract(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}abstract'
    def getValue(self):
        if self.__dict__['abstract']:
            return self.__dict__[utils.property2variable('abstract')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('abstract')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}abstract')
        return elmt

class DAVAcl(DAVElement):
    def __init__(self, aceList=list(), ):
        self.children = ['aceList']
        if aceList:
            self.aceList = aceList
        else:
            self.aceList = list()
    def getTag(self):
        return '{DAV:}acl'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}ace':
                self.aceList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}acl')
        if self.aceList:
            for one in self.aceList:
                elmt.append(one.getXMLElement())
        return elmt
    def update(self, acl):
        for newace in acl.aceList:
            flag = True
            for oldace in self.aceList:
                if newace == oldace:
                    flag = False
                    oldace.update(newace)
            if flag:
                self.aceList.append(newace)

class DAVAuthenticated(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}authenticated'
    def getValue(self):
        if self.__dict__['authenticated']:
            return self.__dict__[utils.property2variable('authenticated')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('authenticated')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}authenticated')
        return elmt

class DAVGrant(DAVElement):
    def __init__(self, privilegeList=list(), ):
        self.children = ['privilegeList']
        if privilegeList:
            self.privilegeList = privilegeList
        else:
            self.privilegeList = list()
    def getTag(self):
        return '{DAV:}grant'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}privilege':
                self.privilegeList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}grant')
        if self.privilegeList:
            for one in self.privilegeList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVWrite(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}write'
    def getValue(self):
        if self.__dict__['write']:
            return self.__dict__[utils.property2variable('write')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('write')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}write')
        return elmt

class DAVSupported_privilege(DAVElement):
    def __init__(self, privilege=None, ):
        self.children = ['privilege']
        if privilege:
            self.privilege = privilege
        else:
            self.privilege = None
    def getTag(self):
        return '{DAV:}supported-privilege'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}privilege':
                self.privilege = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}supported-privilege')
        if self.privilege:
            elmt.append(self.privilege.getXMLElement())
        return elmt

class DAVStatus(DAVElement):
    def __init__(self, status=str(), ):
        self.children = ['status']
        if status:
            self.status = status
        else:
            self.status = str()
        pass
    def getTag(self):
        return '{DAV:}status'
    def getValue(self):
        if self.__dict__['status']:
            return self.__dict__[utils.property2variable('status')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('status')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.status = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}status')
        if self.status:
            elmt.text = self.status
        return elmt

class DAVDescription(DAVElement):
    def __init__(self, description=str(), ):
        self.children = ['description']
        if description:
            self.description = description
        else:
            self.description = str()
        pass
    def getTag(self):
        return '{DAV:}description'
    def getValue(self):
        if self.__dict__['description']:
            return self.__dict__[utils.property2variable('description')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('description')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.description = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}description')
        if self.description:
            elmt.text = self.description
        return elmt

class DAVSupported_privilege_set(DAVElement):
    def __init__(self, supported_privilegeList=list(), ):
        self.children = ['supported_privilegeList']
        if supported_privilegeList:
            self.supported_privilegeList = supported_privilegeList
        else:
            self.supported_privilegeList = list()
    def getTag(self):
        return '{DAV:}supported-privilege-set'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}supported-privilege':
                self.supported_privilegeList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}supported-privilege-set')
        if self.supported_privilegeList:
            for one in self.supported_privilegeList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVCollection(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}collection'
    def getValue(self):
        if self.__dict__['collection']:
            return self.__dict__[utils.property2variable('collection')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('collection')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}collection')
        return elmt

class DAVResponse(DAVElement):
    def __init__(self, hrefList=list(), status=None, propstatList=list(), error=None, responsedescription=None, location=None, ):
        self.children = ['hrefList', 'status', 'propstatList', 'error', 'responsedescription', 'location']
        if hrefList:
            self.hrefList = hrefList
        else:
            self.hrefList = list()
        if status:
            self.status = status
        else:
            self.status = None
        if propstatList:
            self.propstatList = propstatList
        else:
            self.propstatList = list()
        if error:
            self.error = error
        else:
            self.error = None
        if responsedescription:
            self.responsedescription = responsedescription
        else:
            self.responsedescription = None
        if location:
            self.location = location
        else:
            self.location = None
    def getTag(self):
        return '{DAV:}response'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}href':
                self.hrefList.append(DAVElementFactory.CreateByXML(one))
            elif one.tag == '{DAV:}status':
                self.status = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}propstat':
                self.propstatList.append(DAVElementFactory.CreateByXML(one))
            elif one.tag == '{DAV:}error':
                self.error = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}responsedescription':
                self.responsedescription = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}location':
                self.location = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}response')
        if self.hrefList:
            for one in self.hrefList:
                elmt.append(one.getXMLElement())
        if self.status:
            elmt.append(self.status.getXMLElement())
        if self.propstatList:
            for one in self.propstatList:
                elmt.append(one.getXMLElement())
        if self.error:
            elmt.append(self.error.getXMLElement())
        if self.responsedescription:
            elmt.append(self.responsedescription.getXMLElement())
        if self.location:
            elmt.append(self.location.getXMLElement())
        return elmt

class DAVDeny(DAVElement):
    def __init__(self, privilegeList=list(), ):
        self.children = ['privilegeList']
        if privilegeList:
            self.privilegeList = privilegeList
        else:
            self.privilegeList = list()
    def getTag(self):
        return '{DAV:}deny'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}privilege':
                self.privilegeList.append(DAVElementFactory.CreateByXML(one))
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}deny')
        if self.privilegeList:
            for one in self.privilegeList:
                elmt.append(one.getXMLElement())
        return elmt

class DAVCreationdate(DAVElement):
    def __init__(self, creationdate=str(), ):
        self.children = ['creationdate']
        if creationdate:
            self.creationdate = creationdate
        else:
            self.creationdate = str()
        pass
    def getTag(self):
        return '{DAV:}creationdate'
    def getValue(self):
        if self.__dict__['creationdate']:
            return self.__dict__[utils.property2variable('creationdate')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('creationdate')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.creationdate = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}creationdate')
        if self.creationdate:
            elmt.text = self.creationdate
        return elmt

class DAVPropstat(DAVElement):
    def __init__(self, prop=None, status=None, error=None, responsedescription=None, ):
        self.children = ['prop', 'status', 'error', 'responsedescription']
        if prop:
            self.prop = prop
        else:
            self.prop = None
        if status:
            self.status = status
        else:
            self.status = None
        if error:
            self.error = error
        else:
            self.error = None
        if responsedescription:
            self.responsedescription = responsedescription
        else:
            self.responsedescription = None
    def getTag(self):
        return '{DAV:}propstat'
    def getValue(self):
        return self.dumpXML(encoding=None)
    def setValue(self, value):
        self.loadXML(value)
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        for one in xml.getchildren():
            if False:
                pass
            elif one.tag == '{DAV:}prop':
                self.prop = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}status':
                self.status = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}error':
                self.error = DAVElementFactory.CreateByXML(one)
            elif one.tag == '{DAV:}responsedescription':
                self.responsedescription = DAVElementFactory.CreateByXML(one)
            else:
                # raise XMLParsingError, ElementTree.tostring(one)
                pass
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}propstat')
        if self.prop:
            elmt.append(self.prop.getXMLElement())
        if self.status:
            elmt.append(self.status.getXMLElement())
        if self.error:
            elmt.append(self.error.getXMLElement())
        if self.responsedescription:
            elmt.append(self.responsedescription.getXMLElement())
        return elmt

class DAVDepth(DAVElement):
    def __init__(self, depth=str(), ):
        self.children = ['depth']
        if depth:
            self.depth = depth
        else:
            self.depth = str()
        pass
    def getTag(self):
        return '{DAV:}depth'
    def getValue(self):
        if self.__dict__['depth']:
            return self.__dict__[utils.property2variable('depth')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('depth')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
        self.depth = xml.text
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}depth')
        if self.depth:
            elmt.text = self.depth
        return elmt

class DAVPreserved_live_properties(DAVElement):
    def __init__(self, ):
        self.children = []
        pass
    def getTag(self):
        return '{DAV:}preserved-live-properties'
    def getValue(self):
        if self.__dict__['preserved-live-properties']:
            return self.__dict__[utils.property2variable('preserved-live-properties')]
        else:
            return ''
    def setValue(self, value):
        self.__dict__[utils.property2variable('preserved-live-properties')] = value
    def loadXML(self, xml):
        if isinstance(xml, (str, unicode)):
            try:
                xml = ElementTree.XML(xml)
            except:
                raise ValueError, xml
    def getXMLElement(self):
        elmt = ElementTree.Element('{DAV:}preserved-live-properties')
        return elmt

if __name__ == '__main__':
    print(bool(DAVAll()))
    print(bool(DAVMultistatus()))
    error_xml = '<D:error xmlns:D="DAV:"><D:lock-token-submitted><D:href>/locked/</D:href></D:lock-token-submitted></D:error>'
    error = DAVError()
    error.loadXML(error_xml)
    print(error.dumpXML())

    multistatus_xml = '''
     <d:multistatus xmlns:d="DAV:">
       <d:response>
         <d:href>http://www.example.com/container/resource3</d:href>
         <d:status>HTTP/1.1 423 Locked</d:status>
         <d:error><d:lock-token-submitted/></d:error>
       </d:response>
     </d:multistatus>
'''
    multistatus = DAVMultistatus()
    multistatus.loadXML(multistatus_xml)
    print(multistatus.dumpXML())

    propfind_xml = '''
<propfind xmlns="DAV:"><prop><getcontentlength xmlns="DAV:"/><getlastmodified xmlns="DAV:"/><resourcetype xmlns="DAV:"/></prop></propfind>
'''
    propfind = DAVElementFactory.CreateByXML(propfind_xml)
    print(propfind.dumpXML())

    r = dav_resource.Resource('/r1.txt')
    glbl = DAVPrincipal(href=DAVHref(href='/users/global'))
    jhl = DAVPrincipal(href=DAVHref(href='/users/jianghailong'))
    dzp = DAVPrincipal(href=DAVHref(href='/users/dengzhiping'))
    zxy = DAVPrincipal(href=DAVHref(href='/users/zengxinyan'))
    global_pvs = r.getCurrent_user_privilege_set(glbl)
    jhl_pvs = r.getCurrent_user_privilege_set(jhl)
    dzp_pvs = r.getCurrent_user_privilege_set(dzp)
    zxy_pvs = r.getCurrent_user_privilege_set(zxy)
    read_pv = DAVPrivilege(read=DAVRead())
    write_pv = DAVPrivilege(read=DAVWrite())
    print(read_pv in global_pvs)
    print(read_pv in jhl_pvs)
    print(read_pv in dzp_pvs)
    print(read_pv in zxy_pvs)

    acl_1 = DAVAcl()
    acl_1.loadXML('''
<ns0:acl xmlns:ns0="DAV:">
  <ns0:ace>
    <ns0:principal>
      <ns0:property><ns0:owner /></ns0:property>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:all /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
  <ns0:ace>
    <ns0:principal>
      <ns0:property><ns0:group /></ns0:property>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:read /></ns0:privilege>
      <ns0:privilege><ns0:write-content /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
</ns0:acl>
''')
    acl_2 = DAVAcl()
    acl_2.loadXML('''
<ns0:acl xmlns:ns0="DAV:">
  <ns0:ace>
    <ns0:principal>
      <ns0:href>/groups/gdufs</ns0:href>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:read /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
  <ns0:ace>
    <ns0:principal>
      <ns0:href>/groups/netease</ns0:href>
    </ns0:principal>
    <ns0:deny>
      <ns0:privilege><ns0:write-content /></ns0:privilege>
    </ns0:deny>
  </ns0:ace>
  <ns0:ace>
    <ns0:principal>
      <ns0:href>/users/jianghailong</ns0:href>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:read-acl /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
  <ns0:ace>
    <ns0:principal>
      <ns0:href>/users/zengxinyan</ns0:href>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:write /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
</ns0:acl>''')
    acl_1.update(acl_2)
    print(acl_1.dumpXML())

    acl_3 = DAVAcl()
    acl_3.loadXML('''
<ns0:acl xmlns:ns0="DAV:">
  <ns0:ace>
    <ns0:principal>
      <ns0:property><ns0:owner /></ns0:property>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:all /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
  <ns0:ace>
    <ns0:principal>
      <ns0:property><ns0:group /></ns0:property>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:read /></ns0:privilege>
      <ns0:privilege><ns0:write-content /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
</ns0:acl>''')
    acl_4 = DAVAcl()
    acl_4.loadXML('''
<ns0:acl xmlns:ns0="DAV:">
  <ns0:ace>
    <ns0:principal>
      <ns0:href>/users/zengxinyan</ns0:href>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:write /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
  <ns0:ace>
    <ns0:principal>
      <ns0:property><ns0:group /></ns0:property>
    </ns0:principal>
    <ns0:grant>
      <ns0:privilege><ns0:write-acl /></ns0:privilege>
    </ns0:grant>
  </ns0:ace>
</ns0:acl>''')
    acl_3.update(acl_4)
    print(acl_3.dumpXML())

